package com.yulebaby.callsenter.task;

import android.app.Activity;

import com.lzy.okgo.model.HttpParams;
import com.yulebaby.callsenter.global.Constant;
import com.yulebaby.callsenter.http.HttpHelper;
import com.yulebaby.callsenter.http.ServerUrls;
import com.yulebaby.callsenter.http.callback.HttpCallback;
import com.yulebaby.callsenter.utils.SPUtil;

/**
 * 登录
 * Author: Zhangbo
 * Time: 2016/11/16
 */
public class LoginTask {

    /**
     * 登录
     *
     * @param activity     访问网络的Activity
     * @param username     访问的用户名
     * @param password     访问的密码
     * @param httpCallback 回调
     */
    public static void doLogin(Activity activity, String username, String password, HttpCallback httpCallback) {
        HttpParams params = new HttpParams();
        params.put("username", username, false);
        params.put("password", password, false);
        HttpHelper.getInstance().post(activity, ServerUrls.OPT_LOGIN, params, httpCallback);
    }

    /**
     * 退出登录
     *
     * @param activity
     * @param httpCallback
     */
    public static void doLogout(Activity activity, HttpCallback httpCallback) {
        HttpParams httpParams = new HttpParams();
        String user_token = (String) SPUtil.get(Constant.USER_TOKEN, "");
        httpParams.put("token", user_token);
        HttpHelper.getInstance().post(activity, ServerUrls.OPT_LOGOUT, httpParams, httpCallback);
    }
}
